﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class MembershipCard_mobile_Index : WeiPage
{
    PersonInfoBO pbo = new PersonInfoBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["code"] != null)
            {
                try
                {
                    string url = string.Format(@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + GetAppid() + "&secret=" + GetSecret() + "&code={0}&grant_type=authorization_code", Request.QueryString["code"].ToString());
                    string token = PostRequest(url);
                    if (token.Contains("7200"))
                    {
                        string[] b = token.Split('\"');
                        Session["FromUserName"] = b[13];
                        Session["ToUserName"] = "wx8ecea9aaa3d6162b";
                    }
                }
                catch (Exception)
                {

                }
            }
            if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
            {
                string user = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
                string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
                Session["FromUserName"] = user;
                Session["ToUserName"] = user2;
                PersonInfo p = pbo.GetModel(user);
                if (p != null)
                {
                    jf.InnerHtml = "积分：" + p.SurplusIntegral + " <bdo>等级：" + p.MEM_LEVEL + "</bdo>";
                    hyk.Visible = false;
                }
                else
                {
                    hyk.Visible = true;
                    tr1.Visible = false;
                    tr2.Visible = false;
                    tr3.Visible = true;
                    tr4.Visible = true;
                    Response.Redirect("index2.aspx");
                }

            }
        }

    }

    private string GetNum(int id)
    {
        if (id < 10)
            return "000" + id;
        if (id < 100)
            return "00" + id;
        if (id < 1000)
            return "0" + id;
        else return id.ToString();
    }
}